﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

using Meqs.Entity;
using Meqs.Entity.Views;
using Meqs.Logic.Interface;

namespace Meqs.Logic.Implement
{
    public class TeacherRolesLogic : CommonLogic<TeacherRoles, int>, ITeacherRolesLogic
    {
        /// <sammury>
        /// 创建对象
        /// </sammury>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Create(TeacherRoles entity)
        {
            return CreateObject(entity);

        }

        /// <sammury>
        /// 更新对象
        /// </sammury>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Update(TeacherRoles entity)
        {
            return UpdateObject(entity);
        }

        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="entityId"></param>
        /// <returns></returns>
        public int Delete(int entityId)
        {
            return DeleteObject(entityId);
        }

        /// <summary>
        /// 删除所有对象
        /// </summary>
        /// <returns></returns>
        public int DeleteAll()
        {
            return DeleteAllObject();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entityId"></param>
        /// <returns></returns>
        public TeacherRoles FindById(int entityId)
        {
            return FindObjectById(entityId);
        }

        /// <summary>
        /// 检索对象数量
        /// </summary>
        /// <returns></returns>
        public int FindCount()
        {
            return FindObjectByCount();
        }

        /// <sammury>
        /// 检索对象
        /// </sammury>
        public IList<TeacherRoles> FindAll()
        {
            return FindAllObject();
        }

        /// <summary>
        /// 检索对象数量
        /// </summary>
        /// <returns></returns>
        public int FindCount(Hashtable table)
        {
            return FindObjectByCount(table);
        }

        /// <sammury>
        /// 检索对象
        /// </sammury>
        public IList<TeacherRoles> FindAll(Hashtable table)
        {
            return FindObject(table);
        }

        /// <summary>
        /// 获取行政人员名单
        /// </summary>
        public IList<TeacherRoleInfoView> FindTeacherInStaff(int id, String schoolMark, int scholYear, int term)
        {
            try
            {
                Hashtable ht = new Hashtable();
                ht.Add("RoleId", id);
                ht.Add("SchoolMark", schoolMark);
                ht.Add("SchoolYear", scholYear);
                ht.Add("Term", term);
                return FindCustomer<TeacherRoleInfoView>("TeacherRoles.FindTeachInStaff", ht);
            }
            catch (Exception)
            {
                return null;
            }
        }

        /// <summary>
        /// 获取年级组名单
        /// </summary>
        public IList<TeacherRoleInfoView> FindTeacherInGrade(int id, String schoolMark, int scholYear, int term)
        {
            try
            {
                Hashtable ht = new Hashtable();
                ht.Add("Grade", id);
                ht.Add("SchoolMark", schoolMark);
                ht.Add("SchoolYear", scholYear);
                ht.Add("Term", term);
                return FindCustomer<TeacherRoleInfoView>("TeacherRoles.FindTeacherInGrade", ht);
            }
            catch (Exception)
            {
                return null;
            }
        }


        /// <summary>
        /// 获取教研组名单
        /// </summary>
        public IList<TeacherRoleInfoView> FindTeacherInSubject(int id, String schoolMark, int scholYear, int term)
        {
            try
            {
                Hashtable ht = new Hashtable();
                ht.Add("CauseID", id);
                ht.Add("SchoolMark", schoolMark);
                ht.Add("SchoolYear", scholYear);
                ht.Add("Term", term);
                return FindCustomer<TeacherRoleInfoView>("TeacherRoles.FindTeacherInSubject", ht);
            }
            catch (Exception)
            {
                return null;
            }
        }

        /// <summary>
        /// 获取所有代课教师
        /// </summary>
        /// <param name="schoolMark"></param>
        /// <param name="scholYear"></param>
        /// <param name="term"></param>
        /// <param name="roleKey">null-所有身份的教工，任课老师-Class_Teacher，班主任-Class_Header等</param>
        /// <returns></returns>
        public IList<TeacherRoleInfoView> FindAllTeachers(String schoolMark, int scholYear, int term, string roleKey)
        {
            try
            {
                Hashtable ht = new Hashtable();
                ht.Add("SchoolMark", schoolMark);
                ht.Add("SchoolYear", scholYear);
                ht.Add("Term", term);
                if(roleKey != null)
                    ht.Add("roleKey", roleKey);
                return FindCustomer<TeacherRoleInfoView>("TeacherRoles.FindAllTeachers", ht);
            }
            catch (Exception)
            {
                return null;
            } 
        }

        public int DeleteBy(Hashtable ht)
        {
            try
            {
                string statementName = "TeacherRoles.Delete";
                return ExecuteDelete(statementName, ht);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        /// <summary>
        /// 学期升级时权限表升级
        /// </summary>
        /// <param name="schoolMark"></param>
        /// <param name="schoolYear"></param>
        /// <returns></returns>
        public int UpdateTerm(String schoolMark, int schoolYear)
        {
            try
            {
                Hashtable ht = new Hashtable();
                ht.Add("SchoolMark", schoolMark);
                ht.Add("SchoolYear", schoolYear);

                InsertCustomer("TeacherRoles.UpdateTerm", ht);
            }
            catch (Exception ex)
            {
                return -1;
            }
            return 0;
        }
        public IList<TeacherRoles> FindTeacherLeader(String schoolMark, int scholYear, int term)
        {
            try
            {
                Hashtable ht = new Hashtable();
                ht.Add("SchoolMark", schoolMark);
                ht.Add("SchoolYear", scholYear);
                ht.Add("Term", term);
                return FindCustomer<TeacherRoles>("TeacherRoles.FindTeacherLeader", ht);
            }
            catch (Exception ex)
            {
                return new List<TeacherRoles>();
            }
        }
    }
}